<template>
	<view class="box">

		<view class="li" v-for="item in cherList" :key="item.id">
			<view class="left">
				<view class="yuan-l"></view>
				<view class="yuan-r"></view>
				<view class="xian"></view>
				<view class="price">
					<view class="" style="font-size: 24rpx;">
						￥
					</view>
					<view class="" style="font-size: 36rpx;">
						{{item.price}}
					</view>
				</view>
				<view class="name">
					代金券
				</view>
				<view class="bottom">
					满{{item.arrive_price}}可用
				</view>
			</view>

			<view class="right">
				<view class="title">
					{{item.title}}
				</view>
				<view class="con">
					<view class="le">
						<view class="pric">
							<view class="l">
								￥
							</view>
							<view class="p">
								{{item.threshold_price}}
							</view>
						</view>
						<view class="k">
							限购{{item.limit_num}}张
						</view>
					</view>
					<view class="btn" @click="drawFn(item.id)">
						立即领取
					</view>
				</view>
				<view class="tags">
					<view class="tag" v-for="e in item.label">
						{{e}}
					</view>
				</view>
			</view>
		</view>
		<view class="fanhui" @click="fanhui">
			返回
		</view>
	</view>
</template>

<script>
	import {
		UserApi
	} from '@/api';
	export default {
		data() {
			return {
				cherList: []
			};
		},
		async onLoad() {
			try {
				const res = await UserApi.voucherList()
				this.cherList = res.result
			} catch (e) {
				//TODO handle the exception
			}
		},
		methods: {
			fanhui() {
				uni.navigateBack({
					delta: 1
				})
			},
			async drawFn(voucher_id) {
				try {
					const res = await UserApi.purchaseVoucher({
						voucher_id
					})
					const u_res = await UserApi.VoucherPay({
						voucher_id: res.result.id
					})
					// this.$showToast(res.msg)
				} catch (e) {
					//TODO handle the exception
					this.$showToast(e)
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		padding: 25rpx;
		box-sizing: border-box;
		width: 100vw;
		padding-bottom: 200rpx;


		.fanhui {
			position: fixed;
			bottom: calc(30rpx + constant(safe-area-inset-bottom));
			bottom: calc(30rpx + env(safe-area-inset-bottom));
			left: 30rpx;
			width: 690rpx;
			height: 88rpx;
			border-radius: 50rpx;
			opacity: 1;
			background: linear-gradient(173.2deg, #f8b280 0%, #ff8b38 100%);
			text-align: center;
			line-height: 88rpx;
			color: #fff;
			font-size: 30rpx;
		}

		.li {
			width: 700rpx;
			height: 249rpx;
			border-radius: 19rpx;
			opacity: 1;
			background: #ffffff;
			box-sizing: border-box;
			padding: 30rpx;
			display: flex;
			margin-bottom: 30rpx;

			.right {
				flex: 1;
				margin-left: 30rpx;

				.title {
					font-size: 30rpx;
					font-weight: 400;
					margin-bottom: 22rpx;
				}

				.tags {
					display: flex;
					align-items: center;

					.tag {
						width: 98rpx;
						height: 34rpx;
						text-align: center;
						line-height: 34rpx;
						border-radius: 5rpx;
						color: #fb8b07;
						background: #ffeedb;
						font-size: 20rpx;
						margin-right: 15rpx;
					}
				}

				.con {
					display: flex;
					align-items: center;
					justify-content: space-between;
					width: 100%;
					margin-bottom: 15rpx;

					.btn {
						width: 188rpx;
						height: 64rpx;
						border-radius: 32rpx;
						opacity: 1;
						background: #fb8b07;
						font-size: 32rpx;
						color: #fff;
						text-align: center;
						line-height: 64rpx;
					}

					.le {
						.k {
							font-size: 24rpx;
							color: #bbb;
							margin-top: 15rpx;
						}

						.pric {
							display: flex;
							align-items: flex-end;
							color: #ff6f00;
							font-size: 32rpx;

							.l {
								font-size: 24rpx;
							}
						}
					}
				}
			}



			.left {
				width: 166rpx;
				height: 189rpx;
				border-radius: 15rpx;
				opacity: 1;
				background: linear-gradient(180deg, #ff6f00 0%, #de4c00 100%);
				position: relative;
				box-sizing: border-box;
				padding: 30rpx 0;
				text-align: center;

				.price {
					color: #fff;
					display: flex;
					justify-content: center;
					align-items: flex-end;
				}

				.bottom {
					// position: absolute;
					// // left: 28rpx;
					// bottom: 24rpx;
					font-size: 22rpx;
					color: #fff;
					margin-top: 34rpx;
				}

				.name {
					color: #ffffff;
					font-size: 22rpx;
					font-weight: 400;
				}

				.xian {
					position: absolute;
					left: 27rpx;
					bottom: 63rpx;
					width: 112rpx;
					height: 0;
					opacity: 0.33000001311302185;
					border: 1rpx solid #ffffff;
				}

				.yuan-l {
					position: absolute;
					bottom: 47rpx;
					left: -18rpx;
					width: 36rpx;
					height: 36rpx;
					opacity: 1;
					background: #ffffff;
					border-radius: 50%;
				}

				.yuan-r {
					position: absolute;
					bottom: 47rpx;
					right: -18rpx;
					width: 36rpx;
					height: 36rpx;
					opacity: 1;
					background: #ffffff;
					border-radius: 50%;
				}
			}
		}
	}
</style>